/*
 * @Description: 
 * @Author: fhw
 * @Date: 2022-12-07 14:01:37
 */
import { HttpService } from '@nestjs/axios';
import { Injectable, Logger, UseFilters } from '@nestjs/common';
import { firstValueFrom, catchError } from 'rxjs';
import { HttpExceptionFilter } from 'src/http-exception.filter';

@Injectable()
export class EpidemicSituationService {
    private readonly logger = new Logger(EpidemicSituationService.name);
    constructor(private readonly httpService: HttpService) { }
    @UseFilters(new HttpExceptionFilter())
    async getDomesticRiskArea() {
        const showapi_appid = '1289425'
        const showapi_sign = 'e87a3da9b6d640efa0daaf548f21fac3'
        const { data } = await firstValueFrom(
            this.httpService.post<any>(
                `https://route.showapi.com/2217-7?showapi_appid=${showapi_appid}&showapi_sign=${showapi_sign}&area=广州`,
                {}
            ).pipe(
                catchError((error: any) => {
                    this.logger.error(error.response.data);
                    throw 'An error happened!';
                }),
            ),
        );
        const { dangerAreas } = data.showapi_res_body.list[0].cityList[0]
        for (const iterator of dangerAreas) {
            
        }
        return data
    }
}
